<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<!--
location对象的使用
-->

<button>baidu</button>
<button>刷新</button>
<button>页面替换</button>
<script>

    console.log(window.location)
    // location 属性值获取
    console.log(window.location.host)
    console.log(window.location.hostname)
    console.log(window.location.href)
    console.log(window.location.port)
    console.log(window.location.protocol)

    //页面跳转  会保留历史记录
    document.querySelector('button').onclick = function () {
        window.location.href = "http://www.baidu.com"
    }

    // setTimeout(function (){
    //     window.location.href = "http://www.baidu.com"
    // },2000)

    // 刷新页面
    document.querySelectorAll('button')[1].onclick = function () {
        window.location.reload()
    }

    // 页面替换  不会保留历史记录  history
    document.querySelectorAll('button')[2].onclick = function () {
        window.location.replace("http://www.baidu.com?username=tom&age=20")
    }

    //  获取路径参数
     let params = window.location.search
    console.log(params)

</script>
</body>
</html>
